const app = getApp()
Page({
  data: {
    display: "block",
    jilu:[0,0,0,0,0,0,0,0,0],
    flag:[0,0,0],
    zxflag:[],
    oneflag:false,
    twoflag:false,
   threeflag:false,
   fourflag:false,
   fiveflag:false,
   sixflag:false,
   sevenflag:false,
    // biaoji:1,
    tabbar: {},
    indicatorDots: true,
    autoplay: true,
    interval: 2000,
    imageList:[
      {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/one.png"},
     {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/two.png"},
     {"url":"http://sd.offcn.com/zg/wximg/2021/guoshengkao/three.png"}
  ],
  winWidth: 0,
  currentTab: 0,
  list: [
      {
    title: '省考资料',
    fm: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/f1.png',
    lists: [{
        name: '第一章-申论范文卷1',
        sid: 1,
        biaoji:1

      },
      {
        name: '第一章-申论范文卷2',
        sid: 2,
        biaoji:1
      },
      {
        name: '第二章-申论范文卷3',
        sid: 3,
        biaoji:1
      },
      {
        name: '第二章-申论范文卷4',
        sid: 4,
        biaoji:1
      },
      {
        name: '第三章-申论范文卷5',
        sid: 5,
        biaoji:1
      },
      {
        name: '第三章-申论范文卷6',
        sid: 6,
        biaoji:1
      },
      {
        name: '第四章-申论范文卷7',
        sid: 7,
        biaoji:1
      },
      {
        name: '第四章-申论范文卷8',
        sid: 8,
        biaoji:1
      },
      {
        name: '第五章-申论范文卷9',
        sid: 9,
        biaoji:1
      },
      {
        name: '第五章-申论范文卷10',
        sid: 10,
        biaoji:1
      },
      //申论-习思想篇章
      {
        name: '习近平新时代中国特色社会主义思想学习系列：坚持改善和保障民生',
        sid: 11,
        biaoji:1

      },
      {
        name: '习近平新时代中国特色社会主义思想学习系列：人与自然和谐共生',
        sid: 12,
        biaoji:1
      },
      {
        name: '习近平新时代中国特色社会主义思想学习系列：社会主义核心价值体系',
        sid: 13,
        biaoji:1
      },
      {
        name: '习近平新时代中国特色社会主义思想学习系列：四个全面',
        sid: 14,
        biaoji:1
      },
      {
        name: '习近平新时代中国特色社会主义思想学习系列：五位一体',
        sid: 15,
        biaoji:1
      },
      {
        name: '习近平新时代中国特色社会主义思想学习系列：新发展理念',
        sid: 16,
        biaoji:1
      },
      //行测-典型易错5套题
      {
        name: '《典型易错题集-行测1》',
        sid: 17,
        biaoji:1
      },
      {
        name: '《典型易错题集-行测2》',
        sid: 18,
        biaoji:1
      },
      {
        name: '《典型易错题集-行测3》',
        sid: 19,
        biaoji:1
      },
      {
        name: '《典型易错题集-行测4》',
        sid: 20,
        biaoji:1
      },
      {
        name: '《典型易错题集-行测5》',
        sid: 21,
        biaoji:1
      },
      // 行测-解题思路拆解
      {
        name: '《咬文嚼字——行测文科核心考点思路拆解》',
        sid: 22,
        biaoji:1
      },
      {
        name: '《有条有理——行测理科核心考点思路拆解》',
        sid: 23,
        biaoji:1
      },
      {
        name: '2022年山东省考行测判断推理常用的4大推理规则',
        sid: 24,
        biaoji:1
      },
      // 行测-四项考点荟萃
      {
        name: '地理常识（含答案）',
        sid: 25,
        biaoji:1
      },
      {
        name: '法律常识（含答案）',
        sid: 26,
        biaoji:1
      },
      {
        name: '历史常识',
        sid: 27,
        biaoji:1
      },
      {
        name: '时政热点',
        sid: 28,
        biaoji:1
      },
    ]
  },
  // {
  // title: '行测-四项考点荟萃',
  // fm: 'https://sd.offcn.com/zg/wximg/2021/guoshengkao/f1.png',
  // lists: [
  //     {
  //       name: '地理常识（含答案）',
  //       sid: 25,
  //       biaoji:1
  //     },
  //     {
  //       name: '法律常识（含答案）',
  //       sid: 26,
  //       biaoji:1
  //     },
  //     {
  //       name: '历史常识',
  //       sid: 27,
  //       biaoji:1
  //     },
  //     {
  //       name: '时政热点',
  //       sid: 28,
  //       biaoji:1
  //     },
  // ]
  // }
],
  },
  sczxone(){
    var _=this
    _.setData({
      oneflag:!_.data.oneflag
    })
    wx.setStorage({
      key:"zxoneflag",
      data:_.data.oneflag,
    })
    console.log(_.data.oneflag)
  },
  sczxtwo(){
    var _=this
    _.setData({
      twoflag:!_.data.twoflag
    })
    wx.setStorage({
      key:"zxtwoflag",
      data:_.data.twoflag,
    })
    console.log(_.data.twoflag)
  },
  sczxthree(){
    var _=this
    _.setData({
      threeflag:!_.data.threeflag
    })
    wx.setStorage({
      key:"zxthreeflag",
      data:_.data.threeflag,
    })
    console.log(_.data.threeflag)
  },
  sczxfour(){
    var _=this
    _.setData({
      fourflag:!_.data.fourflag
    })
    wx.setStorage({
      key:"zxfourflag",
      data:_.data.fourflag,
    })
    console.log(_.data.fourflag)
  },
  sczxfive(){
    var _=this
    _.setData({
      fiveflag:!_.data.fiveflag
    })
    wx.setStorage({
      key:"zxfiveflag",
      data:_.data.fiveflag,
    })
    console.log(_.data.fiveflag)
  },
  sczxsix(){
    var _=this
    _.setData({
      sixflag:!_.data.sixflag
    })
    wx.setStorage({
      key:"zxsixflag",
      data:_.data.sixflag,
    })
    console.log(_.data.sixflag)
  },
  sczxseven(){
    var _=this
    _.setData({
      sevenflag:!_.data.sevenflag
    })
    wx.setStorage({
      key:"zxsevenflag",
      data:_.data.sevenflag,
    })
    console.log(_.data.sevenflag)
  },
  link1: function () {
    wx.navigateTo({
      url: '../link/link1/link1'
    })
  },
  link2: function () {
    wx.navigateTo({
      url: '../link/link2/link2'
    })
  },
  link3: function () {
    wx.navigateTo({
      url: '../link/link3/link3'
    })
  },
  link4: function () {
    wx.navigateTo({
      url: '../link/link4/link4'
    })
  },
  link5: function () {
    wx.navigateTo({
      url: '../link/link5/link5'
    })
  },
  link6: function () {
    wx.navigateTo({
      url: '../link/link6/link6'
    })
  },
  link7: function () {
    wx.navigateTo({
      url: '../link/link7/link7'
    })
  },
  topdf(e) {
    var _ = this;
    var phone = wx.getStorageSync('xzlphone')
    if (phone) {
      console.log(e.currentTarget.dataset.sid)
      var sid = e.currentTarget.dataset.sid;
      wx.navigateTo({
        url: '../pdf/pdf?sid=' + sid,
      })
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
      _.setData({
        login: 1
      })
    }
  },
  shoucang(e){
      var _=this
      var phone = wx.getStorageSync('xzlphone')
      if (phone) {
        var i=e.currentTarget.dataset.sid
        var a=_.data.flag[i-1]
        _.data.flag[i-1]=!a
        // console.log(_.data.flag)
        wx.setStorage({
          key:"shoucangarr",
          data:_.data.flag,
          success: function() {
            console.log('写入收藏数组成功')
          },
          fail: function() {
            console.log('写入收藏数组发生错误')
          }  
        })
        var dataarr=_.data.list
        for(var b=0;b<_.data.flag.length;b++)
        {
          if(_.data.flag[b]==true){
            dataarr[0].lists[b].biaoji=0
            console.log(dataarr[0].lists[b].biaoji)
          }
          if(_.data.flag[b]==false||_.data.flag[b]==0){
                  dataarr[0].lists[b].biaoji=1
                  console.log(dataarr[0].lists[b].biaoji)
          }
        }
        _.setData({
          list:dataarr
        })
        wx.setStorage({
          key:"listbc",
          data:_.data.list,
          success: function() {
            console.log('写入数组成功')
          },
          fail: function() {
            console.log('写入数组发生错误')
          }  
        })
        
      } else {
        wx.showToast({
          title: '请先登录',
          icon: 'none',
          duration: 2000
        });
        _.setData({
          login: 1
        })
      }

  },
  swipclick: function (e) {//点击图片触发事件
    // console.log(this.data.imageList[this.data.current].url);
    // console.log(e)
    var _=this
    var phone = wx.getStorageSync('xzlphone')
    if (phone) {
      if(this.data.imageList[this.data.current].url=='http://sd.offcn.com/zg/wximg/2021/guoshengkao/one.png')
      {
        wx.navigateToMiniProgram({
        appId: 'wxca86930ec3e80717',
        path: '',
        envVersion: 'release',// 打开正式版
  
   })
      }
      if(this.data.imageList[this.data.current].url=='http://sd.offcn.com/zg/wximg/2021/guoshengkao/two.png')
      {
        wx.navigateToMiniProgram({
          appId: 'wxca86930ec3e80717',
          path: '',
          envVersion: 'release',// 打开正式版
    
     })
      }
      if(this.data.imageList[this.data.current].url=='http://sd.offcn.com/zg/wximg/2021/guoshengkao/three.png')
      {
        wx.navigateToMiniProgram({
          appId: 'wxca86930ec3e80717',
          path: '',
          envVersion: 'release',// 打开正式版
    
     })
      }
      
    } else {
      wx.showToast({
        title: '请先登录',
        icon: 'none',
        duration: 2000
      });
      _.setData({
        login: 1
      })
    }


},
  bindchange:function(e){//轮播图发生改变
    this.setData({
        current:e.detail.current
    })
},
swichNav: function( e ) {

  var _ = this;

  if( this.data.currentTab === e.target.dataset.current ) {
      return false;
  } else {
      _.setData( {
          currentTab: e.target.dataset.current
      })
  }
},

bindChanget: function( e ) {

  var _ = this;
  _.setData( { currentTab: e.detail.current });

},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var _ = this;
    console.log(options);
    _.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      _.setData({
        page: options.page
      })
    }
    var list = wx.getStorageSync('listbc')
    console.log(list)
    if(list!='')
    {
      _.setData({
        list:list
      })
    }
    var sczhuangtai = wx.getStorageSync('shoucangarr')
    console.log(sczhuangtai)
    if(sczhuangtai!='')
    {
      _.setData({
        flag:sczhuangtai
      })
    }
    console.log(_.data.list)
    wx.setStorage({
      key:"list",
      data:_.data.list,
      success: function() {
        console.log('写入数组成功')
      },
      fail: function() {
        console.log('写入数组发生错误')
      }  
    })
    var oneflag=wx.getStorageSync('zxoneflag')
    var twoflag=wx.getStorageSync('zxtwoflag')
    var threeflag=wx.getStorageSync('zxthreeflag')
    _.setData({
      oneflag:oneflag,
      twoflag:twoflag,
      threeflag:threeflag
    })
  },
  getPhoneNumber(e) {
    var _ = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      _.setData({
        mobile: res.result,
      })
      console.log(res.result)
      wx.setStorageSync('xzlphone', res.result)
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 39,
          mobile: res.result,
          areaCode: _.data.area,
          agent: _.data.geneal,
          pageId: _.data.page
        },
        success: res => {
          console.log(res);
        }
      })
      // wx.setStorageSync('xzlphone', _.data.mobile)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=43819&callback=?', //接收url
        data: {
          phone: _.data.mobile,
          fenxiao: _.data.area,
          geneal: _.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          _.setData({
            login: 0,
            display: "none"
          })
        }
      });



    })

  },

  //选择条目
  tabSelect(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      list: e.currentTarget.dataset.id,
      tabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 2) * 200
    })
  },
  getUserProfile(e) {

  },
  // /**
  //  * 生命周期函数--监听页面初次渲染完成
  //  */
  onReady: function () {
    // app.hidetabbar()
  },

  // /**
  //  * 生命周期函数--监听页面显示
  //  */
  onShow: function () {
    // app.hidetabbar()
  }

})